<#include "../common/layout/__mainlayout.html">
    <#include "../common/__pagination.html">

        <!-- page specific plugin styles -->
        <!--设置面包屑-->
        <#assign pageBreadCrumbs>
            <li class="active"><a href="#">应用管理</a></li>
            <li class="active">编辑最美应用</li>
        </#assign>


        <#assign pageCss>
            <!-- page specific plugin styles -->
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/jquery-ui.custom.css"/>
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/chosen.css"/>
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/datepicker.css"/>
        </#assign>

        <#assign pageJavascript>
            <script src="${ctx}/static/admin/assets/js/jquery.dataTables.js"></script>
            <script src="${ctx}/static/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
            <script src="${ctx}/static/admin/assets/js/ajaxfileupload.js"></script>
            <script src="${ctx}/static/admin/assets/js/bootstrap-wysiwyg.js"></script>

            <script type="text/javascript">
                var $path_assets = "${ctx}/static/admin/assets/";
            </script>
            <script type="text/javascript">
                jQuery(function ($) {
                    $("#firstCategoryId").val(${vo.firstCategoryId!});
                    $("#secCategoryId").val(${vo.secCategoryId!});
                    $("#thirdCategoryId").val(${vo.thirdCategoryId!});

                    //初始化数据展示
                    if (!ace.vars['touch']) {
                        $('.chosen-select').chosen({allow_single_deselect: true});
                        $(window).off('resize.chosen').on('resize.chosen', function () {
                                    $('.chosen-select').each(function () {
                                        var $this = $(this);
                                        $this.next().css({'width': $this.parent().width()});
                                    })
                                }).trigger('resize.chosen');
                        //resize chosen on sidebar collapse/expand
                        $(document).on('settings.ace.chosen', function (e, event_name, event_val) {
                            if (event_name != 'sidebar_collapsed') return;
                            $('.chosen-select').each(function () {
                                var $this = $(this);
                                $this.next().css({'width': $this.parent().width()});
                            })
                        });


                        $('#chosen-multiple-style .btn').on('click', function (e) {
                            var target = $(this).find('input[type=radio]');
                            var which = parseInt(target.val());
                            if (which == 2) $('#form-field-select-4').addClass('tag-input-style');
                            else $('#form-field-select-4').removeClass('tag-input-style');
                        });
                    }

                    $("#firstCategoryId").change(function () {
                        //清除二级下拉列表
                        $("#secCategoryId").empty();
                        $("#thirdCategoryId").empty();
                        if ($(this).val() != 0) {

                            $("#secCategoryId").append($("<option/>").text("--请选择二级分类--").attr("value", "0"));
                            //要请求的二级下拉JSON获取页面
                            var url = "${ctx}/admin/category/categoryList.do";
                            //将选中的一级下拉列表项的id传过去
                            $.getJSON(url, {parentId: $(this).val()}, function (data) {
                                //对请求返回的JSON格式进行分解加载
                                $(data.data).each(function () {
                                    $("#secCategoryId").append($("<option/>").text(this.categoryName).attr("value", this.id));
                                });
                            });
                        }
                    });

                    $("#secCategoryId").change(function () {
                        //清除二级下拉列表
                        $("#thirdCategoryId").empty();
                        if ($(this).val() != 0) {
                            $("#thirdCategoryId").append($("<option/>").text("--请选择三级分类--").attr("value", "0"));
                            //要请求的二级下拉JSON获取页面
                            var url = "${ctx}/admin/category/categoryList.do";
                            //将选中的一级下拉列表项的id传过去
                            $.getJSON(url, {parentId: $(this).val()}, function (data) {
                                //对请求返回的JSON格式进行分解加载
                                $(data.data).each(function () {
                                    $("#thirdCategoryId").append($("<option/>").text(this.categoryName).attr("value", this.id));
                                });
                            });
                        }
                    });

                    function showErrorAlert(reason, detail) {
                        var msg = '';
                        if (reason === 'unsupported-file-type') {
                            msg = "Unsupported format " + detail;
                        }
                        else {
                            //console.log("error uploading file", reason, detail);
                        }
                        $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>' +
                                '<strong>File upload error</strong> ' + msg + ' </div>').prependTo('#alerts');
                    }

                    $('#contentdiv').ace_wysiwyg({
                        toolbar: [
                            'font',
                            null,
                            'fontSize',
                            null,
                            {name: 'bold', className: 'btn-info'},
                            {name: 'italic', className: 'btn-info'},
                            {name: 'strikethrough', className: 'btn-info'},
                            {name: 'underline', className: 'btn-info'},
                            null,
                            {name: 'insertunorderedlist', className: 'btn-success'},
                            {name: 'insertorderedlist', className: 'btn-success'},
                            {name: 'outdent', className: 'btn-purple'},
                            {name: 'indent', className: 'btn-purple'},
                            null,
                            {name: 'justifyleft', className: 'btn-primary'},
                            {name: 'justifycenter', className: 'btn-primary'},
                            {name: 'justifyright', className: 'btn-primary'},
                            {name: 'justifyfull', className: 'btn-inverse'},
                            null,
                            {name: 'createLink', className: 'btn-pink'},
                            {name: 'unlink', className: 'btn-pink'},
                            null,
                            {name: 'insertImage', className: 'btn-success'},
                            null,
                            'foreColor',
                            null,
                            {name: 'undo', className: 'btn-grey'},
                            {name: 'redo', className: 'btn-grey'}
                        ],
                        'wysiwyg': {
                            fileUploadError: showErrorAlert
                        }
                    }).prev().addClass('wysiwyg-style2');



                    $("#softEvaluatingForm").validate({
                        errorElement: 'div',
                        errorClass: 'help-block',
                        focusInvalid: true,
                        highlight: function (e) {
                            $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
                        },
                        success: function (e) {
                            $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                            $(e).remove();
                        },
                        errorPlacement: function (error, element) {
                            if (element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                                var controls = element.closest('div[class*="col-"]');
                                if (controls.find(':checkbox,:radio').length > 1) controls.append(error);
                                else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                            }
                            else if (element.is('.select2')) {
                                error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                            }
                            else if (element.is('.chosen-select')) {
                                error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                            }
                            else error.insertAfter(element.parent());
                        },

                        submitHandler: function (form) {
                            $.ajax({
                                cache: true,
                                type: "POST",
                                url: "${ctx}/admin/soft/evaluating/save.do",
                                data: $('#softEvaluatingForm').serialize(),// 你的formid
                                async: false,
                                error: function (request) {
                                    alert("Connection error");
                                },
                                success: function (data) {
                                    if (data.result == "success") {
                                        window.location="${refer!}";
                                    } else {
                                        alert(data.messages);
                                    }
                                }
                            });
                        },
                        invalidHandler: function (form) {
                        }
                    });
                })
            </script>

            <script type="text/javascript">

                $('#id-input-logo,#id-input-pic').ace_file_input({
                    no_file:'未选择文件 ...',
                    btn_choose:'浏览',
                    btn_change:'更改',
                    droppable:false,
                    onchange:null,
                    thumbnail:false //| true | large
                    //whitelist:'gif|png|jpg|jpeg'
                    //blacklist:'exe|php'
                    //onchange:''
                    //
                });

                function uploadLogo() {
                    $.blockUI();
                    $.ajaxFileUpload({
                        url: "${ctx}/admin/upload/uploadPic.do?inputName=iconFile",            //需要链接到服务器地址
                        dataType: 'text',
                        fileElementId: 'id-input-logo',                        //文件选择框的id属性
                        success: function (data, status) {
                            $.unblockUI();
                            msg = jQuery.parseJSON(jQuery(data).text());
                            if (msg.result == "success") {
                                var upload = msg.data;
                                $("#logo").val(upload);
                                $("#iconImg").attr("src", "${staticHost}"+upload);
                            } else {
                                alert(msg.messages);
                            }
                        }, error: function (data, status, e) {
                            $.unblockUI();
                            alert("上传出错，请重新上传");
                        }
                    });
                }


                function uploadPic() {
                    $.blockUI();
                    $.ajaxFileUpload({
                        url: "${ctx}/admin/upload/uploadPic.do?inputName=picFile",            //需要链接到服务器地址
                        dataType: 'text',
                        fileElementId: 'id-input-pic',                        //文件选择框的id属性
                        success: function (data, status) {
                            $.unblockUI();
                            msg = jQuery.parseJSON(jQuery(data).text());
                            if (msg.result == "success") {
                                var upload = msg.data;
                                $("#picUrl").val(upload);
                                $("#picImg").attr("src", "${staticHost}"+upload);
                            } else {
                                alert(msg.messages);
                            }
                        }, error: function (data, status, e) {
                            $.unblockUI();
                            alert("上传出错，请重新上传");
                        }
                    });
                }

                function delPic(image) {
                    bootbox.confirm({
                                message: "确定删除该Logo?",
                                buttons: {
                                    confirm: {
                                        label: "确定",
                                        className: "btn-primary btn-sm"
                                    },
                                    cancel: {
                                        label: "取消",
                                        className: "btn-sm"
                                    }
                                },
                                callback: function (result) {
                                    if (result) {

                                        screenshotSoftItemId = $(image).parent().parent().children("#screenshotSoftItemId").val();
                                        if (screenshotSoftItemId != "") {
                                            $.get("${ctx}/admin/soft/delScreenshot.do", {id: screenshotSoftItemId}, function (data) {
                                                $(image).parent().parent().remove();
                                            });
                                        } else {
                                            $(image).parent().parent().remove();
                                        }
                                    }
                                }
                            }
                    );
                }

                function delLogo(image) {
                    bootbox.confirm({
                                message: "确定删除该Logo?",
                                buttons: {
                                    confirm: {
                                        label: "确定",
                                        className: "btn-primary btn-sm"
                                    },
                                    cancel: {
                                        label: "取消",
                                        className: "btn-sm"
                                    }
                                },
                                callback: function (result) {
                                    if (result) {
                                        screenshotSoftItemId = $(image).parent().parent().children("#screenshotSoftItemId").val();
                                        if (screenshotSoftItemId != "") {
                                            $.get("${ctx}/admin/soft/delScreenshot.do", {id: screenshotSoftItemId}, function (data) {
                                                $(image).parent().parent().remove();
                                            });
                                        } else {
                                            $(image).parent().parent().remove();
                                        }
                                    }
                                }
                            }
                    );
                }

                function submitSoftEvaluating() {
                    $("#content").val($("#contentdiv").html());
                    $('#softEvaluatingForm').submit();
                }



                function resetSoft(){
                    showDiv = "softDiv";
                    var url="${ctx}/admin/soft/searchSoft.do";
                    softId = $("#softId").val();
                    softName = $("#softName").val();
                    //将选中的一级下拉列表项的id传过去
                    $.getJSON(url, {"id": softId,"softName":softName,"pageSize":20},function (data) {
                        //对请求返回的JSON格式进行分解加载
                        $("#softtbody").empty();
                        $(data).each(function () {
                            content = '<tr><td><div class="radio"><label> <input name="softradio" type="radio" value="'+this.id+'" class="ace" /> <span class="lbl"> </span></label></div></td>'
                            +'<td>'+this.id+'</td>'
                            +'<td>'+this.softName+'</td></tr>'
                            $("#softtbody").append(content);
                        });
                    });
                }
            </script>
        </#assign>
        <@mainlayout pageBreadCrumbs=pageBreadCrumbs pageCss=pageCss pageJavascript=pageJavascript currentMenu="ApplicationFlag">

        <form id="softEvaluatingForm" class="form-horizontal" action="${ctx}/admin/soft/evaluating/save.do"
              method="post">
            <ul class="pager">
                <li class="previous"><a href="${ctx}/admin/soft/evaluating/listSoftEvaluating.html">&larr; 返回</a></li>
            </ul>
            <!---最美应用信息----->
                <div class="row">
                    <div class="col-sm-12">
                        <div class="widget-box">
                            <div class="widget-body">
                                <div class="widget-main">
                                    <div class="form-group">
                                        <label class="control-label col-xs-12 col-sm-2" for="id">最美应用id:</label>

                                        <div class="col-xs-12 col-sm-4">
                                            <div class="clearfix">
                                                <input type="text"  name="id" id="id"  class="form-control col-sm-4 " readonly value="${vo.id!}"/>
                                            </div>
                                        </div>
                                        <label class="control-label col-xs-12 col-sm-2 no-padding-right"  for="title">标题:</label>

                                        <div class="col-xs-12 col-sm-4">
                                            <div class="clearfix">
                                                <input type="text" name="title" id="title"  class="form-control col-sm-4" value="${vo.title!}"/>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--上传ICON块---->
                <div class="row">
                    <div class="col-sm-12">
                        <div class="widget-box">
                            <div class="widget-header">
                                <h4 class="widget-title">上传Logo</h4>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main">
                                    <div class="form-group">
                                        <div class="col-xs-8">
                                            <!-- #section:custom/file-input -->
                                            <input type="file" id="id-input-logo" name="iconFile"/>
                                        </div>
                                        <button type="button" id="id-button-logo" class="btn btn-sm btn-success" onclick="uploadLogo()">
                                            上传 <i class="ace-icon fa fa-arrow-right icon-on-right bigger-60"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main">
                                    <div>
                                        <ul class="ace-thumbnails clearfix">
                                            <li><a id="icon128a" data-rel="colorbox">
                                                <img id="iconImg" name="iconImg" src="${staticHost}${vo.logo!}" width="128"
                                                     height="128" onerror="this.src='${ctx}/static/admin/assets/img/imgerror.png'" />
                                                <input type="hidden" name="logo" id="logo" value="${vo.logo!}">
                                            </a>
                                            </li>
                                            </a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!--上传图片---->
                <div class="row">
                    <div class="col-sm-12">
                        <div class="widget-box">
                            <div class="widget-header">
                                <h4 class="widget-title">上传图片</h4>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main">
                                    <div class="form-group">
                                        <div class="col-xs-8">
                                            <input type="file" id="id-input-pic" name="picFile"/>
                                        </div>
                                        <button type="button" id="id-button-pic" class="btn btn-sm btn-success" onclick="uploadPic()">
                                            上传 <i class="ace-icon fa fa-arrow-right icon-on-right bigger-60"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <div class="widget-body">
                                <div class="widget-main">
                                    <div>
                                        <ul class="ace-thumbnails clearfix">
                                            <li><a id="pic128a" data-rel="colorbox">
                                                <img id="picImg" name="picImg" src="${staticHost}${vo.picUrl!}" width="128"
                                                     height="128" onerror="this.src='${ctx}/static/admin/assets/img/imgerror.png'" />
                                                <input type="hidden" name="picUrl" id="picUrl" value="${vo.picUrl!}">
                                            </a>
                                            </li>
                                            </a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-sm-12">
                        <div class="widget-box">
                            <div class="widget-header">
                                <h4 class="widget-title">基础信息</h4>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main">
                                    <div class="form-group">
                                        <label class="control-label col-xs-12 col-sm-2" for="firstCategoryId">软件分类:</label>
                                        <input type="hidden" name="categoryId" id="categoryId" value="${vo.categoryId!}">
                                        <div class="col-xs-12 col-sm-3">
                                            <div class="clearfix">
                                                <div>
                                                    <select class=" form-control" name="firstCategoryId" id="firstCategoryId">
                                                    <#if readonly?? >readonly=""</#if>
                                                    data-placeholder="请选择一级分类">
                                                    <option value="0">--请选择一级分类--</option>
                                                    <#list firstCatagories as first>
                                                        <option value="${first.id}">
                                                            ${(first.categoryName)!}
                                                        </option>
                                                    </#list>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-xs-12 col-sm-3">
                                            <div class="clearfix">
                                                <div>
                                                    <select class=" form-control" name="secCategoryId" id="secCategoryId">
                                                    <#if readonly?? >readonly=""</#if>
                                                    data-placeholder="请选择二级分类">
                                                    <option value="0">请选择二级分类</option>
                                                    <#if secondCatagories??>
                                                        <#list secondCatagories as sec>
                                                            <option value="${sec.id}">
                                                                ${(sec.categoryName)!}
                                                            </option>
                                                        </#list>
                                                    </#if>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-xs-12 col-sm-3">
                                            <div class="clearfix">
                                                <div>
                                                    <select class=" form-control" name="thirdCategoryId" id="thirdCategoryId">
                                                    <#if readonly?? >readonly=""</#if>
                                                    data-placeholder="请选择三级分类">
                                                    <option value="0">请选择三级分类</option>
                                                    <#if thirdCatagories??>
                                                        <#list thirdCatagories as third>
                                                            <option value="${third.id}">
                                                                ${(third.categoryName)!}
                                                            </option>
                                                        </#list>
                                                    </#if>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--简介-->
                                    <div class="form-group">
                                        <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="summary">简介:</label>

                                        <div class="col-xs-12 col-sm-10">
                                            <div class="clearfix">
                                                <textarea class="required col-xs-12 col-sm-10 " id="summary" name="summary">${vo.summary!}</textarea>
                                            </div>
                                        </div>
                                    </div>

                                    <!--详情-->
                                    <div class="form-group">
                                        <label class="control-label col-xs-12 col-sm-2" for="contentdiv">详情:</label>

                                        <div class="col-sm-10 ">
                                            <div class="wysiwyg-editor " id="contentdiv" name="contentdiv"
                                                 style="border:1px solid #d5d5d5">${vo.content!}</div>
                                            <textarea hidden="hidden" id="content" name="content"></textarea>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!----软件-------->
                <div id="softDiv" class="widget-body ">
                    <div class="widget-main">
                        <div class="form-group">
                            <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="id">应用编号:</label>
                            <div class="col-xs-12 col-sm-3">
                                <div class="clearfix">
                                    <input type="text" name="softId" id="softId" class="col-xs-12 " />
                                </div>
                            </div>
                            <label class="control-label col-xs-12 col-sm-1 no-padding-right" for="id">应用名称:</label>
                            <div class="col-sm-3  ">
                                <div class="clearfix">
                                    <input type="text" name="softName" id="softName" class="col-xs-12 " />
                                </div>
                            </div>
                            <input type="button" id="searchSoftButton" class="btn btn-sm btn-primary" onclick="resetSoft()" value="查询"/>&nbsp;
                        </div>
                    </div>
                    <div class="widget-main">
                        <table id="topicTable" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th width="40" align="center">请选择</th>
                                <th width="40" align="center">应用编号</th>
                                <th width="100" align="center">应用名称</th>
                            </tr>
                            </thead>
                            <tbody id="softtbody">
                            <#if checkSofts??>
                                <#list checkSofts as soft>
                                    <tr>
                                        <td  align="center">
                                            <div class="radio"><label> <input name="softradio" type="radio" class="ace" checked="checked" value="${soft.id!}"/> <span class="lbl"> </span></label></div>
                                        </td>
                                        <td  align="center">${soft.id!}</td>
                                        <td  align="center">${soft.softName!}</td>
                                    </tr>
                                </#list>
                            </#if>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="clearfix form-actions">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn btn-info" type="button" onclick="submitSoftEvaluating()">
                            <i class="ace-icon fa fa-check bigger-110"></i> 保存
                        </button>
                        &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
                        <button class="btn" type="button" onclick="submitSoftEvaluating()">
                            <i class="ace-icon fa fa-undo bigger-110"></i> 取消
                        </button>
                    </div>
                </div>

        </form>
    </@mainlayout>
    <script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
    <script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
